<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <h1>产品列表页面</h1>
  <div>
    <span class="btn">正在上映</span>
    <span class="btn">即将上映</span>
  </div>
  <ul class="content">
    <li>
    </li>
  </ul>

  <script src="./js/axios.js"></script>
  <script>
    const btns = document.querySelectorAll('.btn');
    const content = document.querySelector('.content');

    getData(0);
    btns.forEach((item, index) => {
      item.onclick = () => {
        getData(index)
      }
    })
    // 请求后端数据
    function getData(index) {
      axios.get('/api/list', {
        params: {
          tabIndex: index
        }
      }).then(res => {
        console.log(res, 'res')
        content.innerHTML = res.data.list.map((item => {
          return `
          <li>
            <img src=${item.img} alt=${item.nm}/>
            ${item.nm}
          </li>
          `
        })).join('')
      })
    }

  </script>
</body>

</html>